package com.iaiai.notepad;

import java.util.List;
import java.util.Map;

import com.iaiai.notepad.util.DateUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * <p>
 * Title: FileAdapter.java
 * </p>
 * <p>
 * E-Mail: 176291935@qq.com
 * </p>
 * <p>
 * QQ: 176291935
 * </p>
 * <p>
 * Http: iaiai.iteye.com
 * </p>
 * <p>
 * Create time: 2011-12-4
 * </p>
 * 
 * @author 丸子
 * @version 0.0.1
 */
public class FileAdapter extends BaseAdapter {

	private LayoutInflater mInflater;

	private List<Map<String, Object>> listData; // 数据
	
	private Context context;

	public FileAdapter(Context context, List<Map<String, Object>> listData) {
		this.mInflater = LayoutInflater.from(context);
		this.listData = listData;
		this.context = context;
	}
	
	public void setData(List<Map<String, Object>> listData){
		this.listData = listData;
	}

	public int getCount() {
		return listData.size();
	}

	public Object getItem(int position) {
		return listData.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = mInflater.inflate(R.layout.item, null);

		ImageView imageView = (ImageView) convertView.findViewById(R.id.img);
		TextView filename = (TextView) convertView.findViewById(R.id.filename);
		filename.setText(listData.get(position).get("filename").toString());
		TextView date = (TextView) convertView.findViewById(R.id.date);
		date.setText(listData.get(position).get("date").toString());

		if (Boolean.parseBoolean(listData.get(position).get("type").toString())) { // 如果是文件则读取出最文件大小
			TextView size = (TextView) convertView.findViewById(R.id.size);
			size.setText(listData.get(position).get("size").toString());
			imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.file));
		}else{
			imageView.setImageDrawable(context.getResources().getDrawable(R.drawable.folder));
		}

		return convertView;
	}
}
